<title>任务审核</title>
<div class="layui-card layadmin-header">
	<div class="layui-breadcrumb" lay-filter="breadcrumb" lay-separator=">">
        <a lay-href=""><i class="layui-icon layui-icon-locate"></i>您当前的位置：</a>
		<a><cite class="first-breadcrumb">审核管理</cite></a>
        <a><cite class="second-breadcrumb">任务审核</cite></a>
        <a><cite class="third-breadcrumb"></cite></a>
	</div>
</div>
<style>
    .top-part{
        margin: 12px 0 20px 0;
    }
    .left-card, .right-card, .layui-card{
        border-radius: 4px;
    }
    .right-card{
        height: 425px;
        background: #fff;
    }
    .scroll{
        overflow-y: scroll;
    }
    .task-ul{
        height: 345px;
        padding: 18px 0;
    }
    .task-ul ul{
        height: 100%;
        font-size: 14px;
    }
    .task-ul ul li{
        height: 32px;
        line-height: 32px;
        padding: 0 25px 0 20px;
        cursor: default;
    }
    .task-ul ul li+li:hover{
        background: #DCE7F4;
    }
    .layui-table td[data-field="6"]{
        text-align: left;
    }
    .filling{
        display: inline-block;
        width: 72px;
        height: 18px;
        line-height: 20px;
        font-size: 12px;
        background-color: #53C553;
        border-radius: 9px;
        color: #FEFFFE;
    }
    .left-card{
        margin-bottom: 0;
    }
    .layui-card-header{
        height: 19px;
        line-height: normal;
        padding: 10px;
        background-color: #F6F7F8;
    }
    .layui-card-body{
        padding: 0;
    }
    .card-header-icon{
        width: 18px;
        height: 18px;
    }
    .card-header-title{
        margin-left: 5px;
    }
    .layui-table-view .layui-table th, .layui-table-view .layui-table td{
        width: 286px;
        padding: 4px 0;
        text-align: center;
        vertical-align: middle;
    }
    .layui-tab-content .layui-table th{
        border: 1px solid #e6e6ee;
    }
    .btn-submit, .btn-forward, .btn-assign, .btn-return{
        height: 22px;
        font-size: 12px;
        border-radius: 4px;
    }
    .btn-submit{
        width: 48px;
        border: 1px solid #4BAA0B;
        color: #4BAA0B;
    }
    .btn-forward{
        width: 48px;
        border: 1px solid #1C74D4;
        color: #1C74D4;
    }
    .btn-assign{
        width: 60px;
        border: 1px solid #0078FF;
        color: #0078FF;
    }
    .btn-return{
        width: 62px;
        border: 1px solid #828282;
        color: #828282;
    }
    .layui-fluid{
        padding: 0 15px;
    }

    .undo-task{
        padding-left: 10px;
    }
    .task-content-box{
        float: left;
        width: 70%;
        height: 32px;
        text-overflow: ellipsis;
        overflow: hidden;
    }
    .task-num{
        display: inline-block;
        width: 25px;
        color: #373737;
    }
    .task-content{
        color: #373737;
    }
    .task-time{
        float: right;
        width: 30%;
        height: 32px;
        color:#666666;
        overflow: hidden;
        text-align: right;
    }
    .select-form-header{
        position: relative;
    }
    .card-header-right{
        position: absolute;
        right: 0;
        top: 0;
    }
    .layui-card .layui-tab{
        margin-top: 13px;
        z-index: 9999;
    }
    .layui-tab-card>.layui-tab-title{
        background: #fff;
    }
    .layui-tab-card{
        border-top: none;
    }
    .select-form-box{
        min-height: 400px;
    }
    .layui-tab-content{
        padding: 15px 9px;
    }
    .layui-table tbody tr.bgRed{
        background: red;
    }
    .task-btn-group{
        margin-bottom: 5px;
    }
    .layui-btn-pass, .layui-btn-back, .layui-btn-detail {
        height: 24px;
        background-color: transparent;
        outline: none;
        border: none;
    }
    .layui-btn-detail{
        width: 22px;
        background: url('/dist/style/res/about/detail.png') no-repeat center center;
    }
    .layui-btn-pass{
        width: 23px;
        background: url('/dist/style/res/about/pass.png') no-repeat center center;
    }
    .layui-btn-back{
        width: 24px;
        background: url('/dist/style/res/about/back.png') no-repeat center center;
    }
    .layui-table-view .layui-table{
        width:100%;
    }
    .layui-table-box .layui-table[lay-even] tbody tr.lineactive{
        background-color: #FDE7A3;
    }
    .btn-colla{
        height: 30px;
        line-height: 30px;
        border: none;
        background-color: #F6F7F8;
    }
    .btn-colla .layui-icon{
        right: 7px;
    }
    #usermemo{
        overflow: hidden;
    }
    #usermemo .layui-form-label{
        width: auto;
        padding:  9px 10px;
    }
    .layui-layer-btn .layui-layer-btn0{
        background-color: #2669B1;
        border-color: #2669B1;
    }
    .kqform-content {
        overflow: auto;
    }
    .kq-info-title {
        display: inline-block;
        height: 30px;
        line-height: 30px;
        margin-right: 30px;
    }
    .left-card .no-data-tips{
        margin-top: 70px;
    }
    .task-ul .no-data-tips{
        margin-top: 100px;
    }
    .layui-tab-content .layui-form-select{
        width: 250px;
        margin: auto;
    }
    .height-auto{
        height: 385px;
    }
    .height-max{
        height: 825px;
    }
    .otherForm-content .layui-tab-content{
        overflow: auto;
    }
    .otherForm-content tr th{
        text-align: center;
        min-width: 100px;
    }
    .download-fileBox{
        position: relative;
    }
    .fileAllBox{
        position: absolute;
        left: 14%;
        top: 26px;
        background: #000;
        display: none;
        padding: 6px;
        z-index: 9999;
    }
    .fileAllBox p{
        color: white;
        font-size: 14px;
    }
</style>
<div class="custom-taskReview-page">
    <div class="layui-fluid top-part">
        <div class="layui-row layui-col-space10">
            <div class="layui-col-md12">
                <div class="layui-card left-card">
                    <div class="layui-card-header">
                        <img src="../../../../dist/style/res/formFill/tem-task.png" class="card-header-icon"/>
                        <span class="card-header-title">待审核任务列表</span>
                    </div>
                    <div class="layui-card-body task-to-reviewBox">
                        <table class="layui-hide task-list" id="task-to-review" lay-filter="task-to-review"></table>
                    </div>
                </div>
            </div>
            <div class="layui-col-md3 layui-hide">
                <div class="layui-card right-card">
                    <div class="layui-card-header undo-task">
                        <img src="../../../../dist/style/res/formFill/tem-task.png" class="card-header-icon"/>
                        <span class="card-header-title">待办任务列表</span>
                    </div>
                    <div class="task-ul">
                        <ul class="scroll"></ul>
                    </div>
                </div>
            </div>
      </div>
    </div>
    <div class="layui-fluid">
        <div class="layui-col-md12">
            <div class="layui-card select-form-box" style="margin: 0;">
                <div class="layui-card-header clearfix select-form-header">
                <div class="card-header-left left">
                    <img src="../../../../dist/style/res/formFill/tem-task.png" class="card-header-icon"/>
                    <div class="layui-inline custom-card-header">
                        <span class="card-header-title">填报列表</span>
                        <span class="layui-title-mid layui-hide">-</span>
                        <span class="card-header-subtitle"></span>
                    </div>
                </div>
                <div class="card-header-right right card-header-kq hide">
                    <div class="kq-info-title">
                        <span>填报单位：</span><span class="c-unit"></span>&nbsp;&nbsp;
                        <span>考勤日期：</span><span class="c-startDate"></span>~<span class="c-endDate"></span>
                    </div>
                    <button class="layui-btn layui-btn-primary btn-colla E-btn" data-target="colla">
                        <i class="layui-icon layui-icon-up"></i>
                    </button>
                </div>
                </div>
                <div class="layui-tab otherForm-content" id="task-review-tab" lay-filter='tabSwitch'>
                    <div class="no-data-tips" style="margin: 100px auto;">
                        <img src="/src/style/res/about/empty.png">
                        <p style="color:#DBDBDB;">暂无数据</p>
                    </div>
                </div>
                <div id="audit-form-task-kqform" class="kqform kqform-content"></div>
            </div>
        </div>
    </div>
</div>
<!-- 任务状态模板 -->
<script type="text/html" id="taskState">
    {{#
		var getStatusColor = function() {
			var mapColors = {
                '00': 'layui-bk-green',
                '20': 'layui-bk-gray',
                '25': 'layui-bk-orange',
                '30': 'layui-bk-green',
                '40': 'layui-bk-orange',
                '90': 'layui-bk-gray',
                '99': 'layui-bk-gray'
			};
			return mapColors[d.state] || '';
		};
	}}
	<span class="custom-badge {{getStatusColor()}}">{{d.statename}}</span>	
</script>

<!-- 工具栏模板 -->
<script type="text/html" id="examine">
    <button class="layui-btn layui-btn-primary layui-btn-xs layui-btn-detail layui-hide" lay-event="detail" lay-tips="下发单位"></button>
    <button class="layui-btn layui-btn-primary layui-btn-xs layui-btn-pass" lay-event="pass" lay-tips="通过"></button>
    <button class="layui-btn layui-btn-primary layui-btn-xs layui-btn-back" lay-event="back" lay-tips="退回"></button>
</script>

<!-- 待办任务 -->
<script type="text/html" id="auditTask">
    {{# if(d && d.length > 0){ }}
        <li class="undotask-header">
            <span class="title-num">序号</span>
            <span class="title-content">任务名称</span>
            <span class="title-time">填报结束时间</span>
        </li>
        {{# layui.each(d, function(index, item){ }}
            <li class="clearfix E-btn" data-jump={{item.connection}} data-target="jump">
                <div class="task-content-box">
                    <span class="task-num">{{index+1}}</span>
                    <span class="task-content"  lay-tips={{item.taskname}}>{{item.statename}}-{{item.taskname}}</span>
                </div>
                <div class="task-time">{{item.endtime}}</div>
            </li>
        {{# }); }}
    {{# }else{ }}
        <div class="no-data-tips">
            <img src="/src/style/res/about/empty.png">
            <p style="color:#DBDBDB;">暂无数据</p>
        </div>
    {{# } }}
</script>
<!-- 任务列表附件栏 -->
<script id="download" type="text/html">
    {{# if(!!d.fileNames && d.fileNames.length && d.fileNames.length > 0){     }}
        {{#   layui.each(d.fileNames, function(index, file){ }}
            <a class="download-file" lay-event="download" data-url={{file.url}} lay-tips='{{file.filename}}'>{{file.filename}}</a>
        {{# }); }}    
    {{# } }}
</script>

<!-- 审核表格 -->
<script type="text/html" id="lsczTaskTable">
    {{# if(d && d.length >0) { }}
    <ul class="layui-tab-title">
        {{# layui.each(d, function(index, item){ 
            var showThis = item.showThis ? 'layui-this' : '';
        }}
            <li class="{{showThis}}">{{item.formname}}</li>
        {{# }); }}
    </ul>
    <div class="layui-tab-content">
        {{# layui.each(d, function(index, item){ 
            var showThis = item.showThis ? 'layui-show' : '';
        }}
            <div class="layui-tab-item {{showThis}}">
                {{# if(item.deptMsgs && item.deptMsgs.length > 0){ }}
                    <div>
                        {{# layui.each(item.deptMsgs, function(j, dtem){ }}
                            <input type="radio" name="dept{{index}}" value="{{dtem.dept_id}}" title="{{dtem.dept_name}}" data-index="{{index}}" lay-filter="custom-unit-radio" {{dtem.checked ? "checked" : ""}}/>
                        {{# }) }}
                    </div>
                {{# } }}
                <table class="layui-table">
                    <thead>
                        {{# if(item.cols && item.cols.length > 0){ }}
                            {{# layui.each(item.cols, function(index, col){ }}
                                <tr>
                                    {{# layui.each(col, function(cndex, ctem){ }}
                                        <th colspan="{{ctem.colspan ? ctem.colspan : '1'}}" rowspan="{{ctem.rowspan ? ctem.rowspan : '1'}}">{{ctem.title}}</th>
                                    {{# }) }}
                                </tr>
                            {{# }) }}
                        {{# } }}
                        
                    </thead>
                    <tbody>
                        {{# if(item.data.grid && item.data.grid.length > 0) {
                            layui.each(item.data.grid,function(gdex,gtem) { }}
                                <tr>
                                    {{# layui.each(item.form_field,function(hdex,htem) { }}
                                        <td>{{gtem[htem.fieldenglish]}}</td>
                                    {{# }) }}
                                </tr>
                        {{# 
                            })
                            }else {
                        }}
                        {{# var count = 0;if(item.cols){ }}
                            {{# layui.each(item.cols[0], function(i, col){
                                col.colspan ? count += parseInt(col.colspan) : count += 1;
                            }) }}
                        {{# } }}
                        <tr>
                            <td colspan="{{count}}" style="text-align: center;">暂无数据</td>
                        </tr>
                        {{#
                            }
                        }}
                    </tbody>
                </table>
            </div>
        {{# }) }}
    </div>
    {{# } else{ }}
        <div style="width: 100%;text-align: center;">暂无填报表单</div>
    {{# } }}
</script>

<script>
layui.use(['admin', 'table', 'element', 'tools', 'laytpl', 'form', 'laypage', 'tablePlug'], function(){
    var $ = layui.$,
        layer = layui.layer,
        element = layui.element,
        table = layui.table,
        admin = layui.admin,
        tools = layui.tools,
        view = layui.view,
        laytpl = layui.laytpl,
        router = layui.router(),
        search = router.search,
        form = layui.form,
        laypage = layui.laypage;


    var delRows = [], //删除行数据
        colName = [], //列名
        layout = ['.layui-table th', '.layui-table td', '.task-ul>ul'];
    window.tabIndex = 0; //选项卡下标 默认为0
    window.tableId = 'test-table-cellEdit1'; //选项卡表单id

    getTaskReview();

    //查询常驻任务
    function viewCz(id, checking) {
        var url = checking !== '1' ? 'myapi/DC/api/rest/web/custom/GetTaskMsgsById' : 'myapi/DC/api/rest/web/custom/CheckTaskDataSelect?model=updateSelect';
        var args = {
            id: id
        },
        cArgs = {
            taskid: id
        };
        admin.req({
            url: url,
            data: checking !== '1' ? args : cArgs,
            success: function(res){
                var data = checking !== '1' ? res.data : res.data.data;
                clickForTr(data, data.isChecking);
            }
        });
    }

    //查询临时任务
    function viewLs(id) {
        admin.req({
            url: 'myapi/DC/api/rest/web/custom/GetTaskMsgsById',
            data: {
                id: id
            },
            success: function(res){
                if(res.retcode == '0'){
                    clickForTr(res.data, res.data.isChecking);
                }
            }
        })
    }

    //待审核任务列表
    function getTaskReview(){
        table.render({
            elem: '#task-to-review'
            ,height: 385
            ,url: 'myapi/DC/api/rest/web/custom/TaskAudit'
            ,where: {
                model:'select',
                access_token: layui.data('layuiAdmin').access_token
            }
            ,text: {
                none: '<div class="no-data-tips"><img src="/src/style/res/about/empty.png"><p style="color:#DBDBDB;">暂无数据</p></div>'
            }
            ,request: {
                limitName: 'count'
            }
            ,parseData: function(res){ 
                return {
                    "code": res.retcode, 
                    "msg": res.retmsg, 
                    "count": res.data.totalNumber, 
                    "data": res.data.dataList 
                };
            }
            ,cellMinWidth: 80 
            ,page: {
                groups: 1, 
                limit: 10,
                next:'<i class="layui-icon">&#xe602;</i>',
                prev:'<i class="layui-icon">&#xe603;</i>',
                first: '<i class="layui-icon">&#xe65a;</i>',
                last: '<i class="layui-icon">&#xe65b;</i>',
                layout: ['refresh', 'first', 'prev', 'skip', 'count', 'allPage', 'next', 'last'],
                extend:{
                    first: true,
                    spr: false,
                    pagecount: true
                }
            }
            ,cols: [[
                { type: 'numbers', title: '序号', width: 44 },
                { title: '任务状态', toolbar: '#taskState', width: 105 }
                ,{
                    field:'taskname',
                    title: '任务名称', 
                    width: 260, 
                    templet: function(d){
                        return '<span lay-tips="'+ d.taskname +'">'+ d.taskname +'</span>'
                    }
                }
                ,{field: 'starttime', title: '开始时间', width: 200, 
                    templet: function(d){
                        return '<span lay-tips="'+ d.starttime +'">'+ d.starttime +'</span>'
                    }
                }
                ,{field: 'endtime', title: '结束时间', width: 200, 
                    templet: function(d){
                        return '<span lay-tips="'+ d.endtime +'">'+ d.endtime +'</span>'
                    }
                }
                ,{
                    field:'memo',
                    title: '任务内容',
                    width: 200, 
                    templet: function(d){
                        return '<span lay-tips="'+ d.memo +'">'+ d.memo +'</span>'
                    }
                }  
                ,{ title: '附件', 
                    // toolbar: '#download', 
                    field:'fileNames',
                    templet: function(d){  
                        var newDownLoadBox="";
                        var fileNames=d.fileNames;
                        if(fileNames&&fileNames.length>0){
                            for(var i=0;i<fileNames.length;i++){
                                newDownLoadBox+='<p class="download-file" lay-event="download" data-taskid='+fileNames[i].taskid+' data-url='+fileNames[i].url+' >'+fileNames[i].filename+'</p>'
                            }   
                            return ' <div class="download-fileBox">'+
                                    '<a class="download-file downLoadFileBtn" taskid='+d.taskid+'>下载附件</a>'+  
                                    '<div class="fileAllBox">'+
                                        newDownLoadBox+
                                    '</div>'+
                                    '</div>'
                            
                        }else{
                            return '' 
                        }
                        // <a class="download-file" lay-event="download" data-url={{file.url}} lay-tips='{{file.filename}}'>{{file.filename}}</a>
                    },
                    width: 260
                 }
                ,{ field: 'deptname', title: '单位',width: 160 }
                ,{ field: 'username', title: '提交人',width: 120 }
                ,{ title: '审核操作', toolbar: '#examine',width: 160 }
            ]]
            ,even: true 
            ,done: function(res, curr, count){
                    $(".download-fileBox").parent(".layui-table-cell").css({"overflow":"visible"})
                    $(".download-fileBox").on("mouseover",function(){  
                        $(this).find(".fileAllBox").show();  
                    })
                    $(".download-fileBox").on("mouseout",function(){ 
                        $(this).find(".fileAllBox").hide(); 
                    }) 
                    $(".downLoadFileBtn").click(function(){
                        tools.downLoadMutipleFileFun($(this).attr("taskid")) 
                     })
                if(res.data && res.data.length > 0){
                    var isChecking = res.data[0].checking;
                    //clickForTr(res.data[0], isChecking);
                    window.taskId = res.data[0].id;
                    tools.clickToTask(res.data, router, 'task-to-review'); 
                }else{
                    //清除考勤任务
                    $('#audit-form-task-kqform').empty();
                    $('.kq-info-title .c-unit').text('');
                    $('.kq-info-title .c-startDate').text('');
                    $('.kq-info-title .c-endDate').text('');
                    $('.card-header-kq').addClass('hide');
                    $('.kqform-content').hide();
                    //清理普通任务
                    $('.form-tab-title').empty();
                    $('#'+window.tableId).next().find('.layui-table-box').empty();
                    $('.form-tab-content').empty().html('<div class="no-data-tips"><img src="/src/style/res/about/empty.png"><p style="color:#DBDBDB;">暂无数据</p></div>');
                }
                tools.setFont(layout);
            }
        }); 
    }

    //填报考勤任务表单详情列表加载
    function getKQTaskForm(taskid) {
        admin.req({
            type: 'get',
            url: 'myapi/DC/api/rest/web/custom/TaskAuditForms',
            data: {
                taskid: taskid,
                checking: '1',
            },
            success: function(res) {
                var dates = res.data.users.length > 0 ? res.data.users[0].users_time[0].users_time_day : [],
                    users = res.data.users;
                $('.kq-info-title .c-startDate').text(res.data.starttime ||' 暂无');
                $('.kq-info-title .c-endDate').text(res.data.endtime ||' 暂无');
                view('audit-form-task-kqform').render('./audit/components/kqTaskReview', {
                    dates: dates, 
                    users: users,
                    basic: {
                        dept_code: res.data.dept_code,
                        dept_name: res.data.dept_name,
                        dept_id: res.data.dept_id,
                        taskid: taskid
                    }
                });
                tools.setFont(layout);
            }
        });
    }

    //加载填报表单
    function getTaskForm(taskid){
        admin.req({
            url: 'myapi/DC/api/rest/web/custom/TaskAuditForms',
            data: {
                taskid: taskid,
                access_token: layui.data('layuiAdmin').access_token
            },
            success: function(res) {
                if(res.retcode == '0' && res.data && res.data.length > 0){            
                    var data = res.data;
                    layui.each(data, function(index, item){
                        item.showThis = window.tabIndex == index ? true : false;
                    });
                    var getTpl = lsczTaskTable.innerHTML,
                        viewHtml = document.getElementById('task-review-tab');
                    laytpl(getTpl).render(data, function(html){
                        viewHtml.innerHTML = html;
                    });
                }
            }
        })
    }


    //待办任务
    function getUndoTask(){
        var appid = layui.data('userdata').appId;
        admin.req({
            url: 'myapi/DC/api/rest/web/custom/GetTasksByUserApp',
            data: {
                app_id: appid,
            },
            success: function(res){
                if(res.retcode == '0'){
                    var data = res.data.auditTask.concat(res.data.writeTask),
                        getTpl = auditTask.innerHTML,
                        view = document.querySelector('.task-ul ul');
                    laytpl(getTpl).render(data, function(html){
                        view.innerHTML = html;
                    })
                }
            }
        })
    }

    //获取表头数据
    function getUTable(formhtml, type){
        var div = document.createElement('div');
        div.innerHTML = formhtml;
        var allTh = div.querySelectorAll('table th'),
            allTr = div.querySelectorAll('table tr'),
            colhead = [],
            colbody = [];

        layui.each(allTh, function(index, item){
            var fieldenglish = item.getAttribute('id'),
                fieldname = item.innerText;
            colhead.push({
                field: fieldenglish,
                title: fieldname,
                minWidth: 230
            })
        });

        layui.each(allTr, function(index2, eachTr){
            var rowTd = eachTr.querySelectorAll('td');
            layui.each(rowTd, function(index3, eachTd){
                if(eachTd.innerText != ''){ //表格存在数据时
                    var obj = new Object();
                    layui.each(colhead, function(index4, content){
                        var field = content.field;
                        obj[field] = rowTd[index4].innerText; 
                    })
                    colbody.push(obj);
                    colbody = deteleObject(colbody);
                }
            })
        })
        if(colbody.length  == 0 || colbody.length < 5){ //表格没有数据时，默认添加5个空行
            var len = 5 - colbody.length;
            for(var i = 0; i < len; i++){ 
                var obj = new Object();
                layui.each(colhead, function(index5, item5){
                    var field = item5.field;
                    obj[field] = ''; 
                })
                colbody.push(obj);
            }
        }
        if(type == 'thead'){
            return colhead
        }else{
            return colbody
        }
    }

    //不同任务类型做不同的元素切换
    function pickTypeShow(type) {
        if(type === 'other') {
            $('.otherForm-content').show();
            $('.kqform-content').hide();
            $('.card-header-kq').hide();
        }else if(type === 'kqform') {
            $('.otherForm-content').hide();
            $('.kqform-content').show();
            $('.card-header-kq').show();
        }
    }

    //监听Tab切换
    element.on('tab(tabSwitch)', function(data){
        var index = data.index + 1;
        window.tableId = 'test-table-cellEdit'+index; //表格ID
        window.tabIndex = data.index; //选项卡下标
        getTaskForm(window.taskId);
    })

    //任务列表 => 监听行点击事件
    table.on('row(task-to-review)', function(obj){
        $('[lay-id="task-to-review"]').find(obj.tr.selector).addClass('lineactive');
        $('[lay-id="task-to-review"]').find(obj.tr.selector).siblings().removeClass('lineactive');
        window.taskId = obj.data.id;
        window.tabIndex = 0;
        window.tableId = 'test-table-cellEdit1'; 
        tools.setNavText();
        tools.setTaskFormTitle(obj.data.taskname);
        clickForTr(obj.data, obj.data.checking);
    });

    //行点击事件
    function clickForTr(data,checking) {
        if(checking === '1') {
            getKQTaskForm(data.id);
            $('.kq-info-title .c-unit').text(data.deptname ||' 暂无');
            pickTypeShow('kqform');
        }else {
            getTaskForm(data.id);
            pickTypeShow('other');
        }
    }

    //待办任务点击事件
    $('.task-ul').delegate('li.E-btn', 'click', function(){
        var toJump = $(this).attr('data-jump');
        location.hash = search.redirect ? decodeURIComponent(search.redirect) : '/'+toJump;
    })

    //点击事件
    $('.E-btn').click(function(){
        var target = $(this).data('target');
        if(target == 'colla'){
            var tbHeight = 0,
                flag = $(this).find('.layui-icon').hasClass('layui-icon-up');
            $('.left-card').slideToggle();
            $('.right-card').slideToggle();
            $(this).find('i').toggleClass("layui-icon-up layui-icon-down");
            $(this).parents('.select-form-box').toggleClass('height-auto height-max');
            tbHeight = flag ? 700 : 250;
            table.reload(window.tableId, {
                height: tbHeight
            });
        }
    })

    //监听工具栏按钮
    table.on('tool(task-to-review)', function(obj){
        layui.stope(obj.ev);
        var event = obj.event,
            data = obj.data,
            thisModel = null,
            memoTitle = '';
        if(event == 'pass' || event == 'back'){
            if(event == 'pass'){
                thisModel = 'pass';
                memoTitle = '通过意见';
            }else{
                thisModel = 'back';
                memoTitle = '退回意见';
            }
            layer.open({
                id: 'usermemo',
                type: 1,
                title: '<i class="formFill-icon"></i><span style="color:#FFF;">'+memoTitle+'</span>',
                area: ['300px', '250px'],
                offset: 'auto',
                shadeClose: true,
                resize: false,
                success: function(lay, index){
                    view(this.id).render('./audit/components/usermemo', {
                        showReview: false
                    });
                },
                btn: ['确定', '取消'],
                btnAlign: 'c',
                yes: function(index, layero){
                    var memoval = $('#usermemo .layui-textarea').val();
                    admin.req({
                        url: 'myapi/DC/api/rest/web/custom/TaskAudit',
                        type: 'post',
                        data:{
                            taskid: data.id,
                            model: thisModel,
                            usermemo: memoval
                        },
                        success: function(res){
                            if(res.retcode == '0'){
                                thisModel == 'pass' ? layer.msg('通过成功', {time: 1000}) : layer.msg('退回成功', {time: 1000});
                                layer.close(index);
                                getTaskReview();
                                //getUndoTask();
                            }
                        }
                    })
                },
                btn2: function(index, layero){}
            })
        }else if(event == 'download'){
            var url = 'myapi/DC/'+ $(this).data('url'),
                name = $(this).text(),
                taskid=$(this).data('taskid');
            tools.downMethodfunction(url, name,taskid); 
        }else if(event === 'detail') {
            if(data.tasktype === 'ls') {
                admin.req({
                    url: 'myapi/DC/api/rest/web/custom/GetTaskMsgsById',
                    data: {
                        id: data.id
                    },
                    success: function(res){
                        if(res.retcode == '0'){
                            layer.open({
                                id: 'temporary-viewHtml',
                                title: '<i class="formFill-icon"></i><span style="color:#FFF;">查看临时任务</span>',
                                offset: '20px',
                                type: 1,
                                shadeClose: true,
                                area: ['1133px', '380px'],
                                success: function(lay) {
                                    view(this.id).render('./task/temporary/view', res.data);
                                }
                            });
                        }
                    }
                })
            }else if(data.tasktype === 'cz') {
                var checking = data.checking;
                var url = checking !== '1' ? 'myapi/DC/api/rest/web/custom/GetTaskMsgsById' : 'myapi/DC/api/rest/web/custom/CheckTaskDataSelect?model=updateSelect';
                var args = {
                    id: data.id
                },
                cArgs = {
                    taskid: data.id
                };
                admin.req({
                    url: url,
                    data: checking !== '1' ? args : cArgs,
                    success: function(res){
                        var data = checking !== '1' ? res.data : res.data.data;
                        layer.open({
                            id: checking !== '1' ? 'permanent-viewhtml' : 'attence-viewhtml',
                            title: checking !== '1' ? '查看常驻任务' : '查看考勤任务',
                            offset: '20px',
                            type: 1,
                            shadeClose: true,
                            area: checking !== '1' ? ['1133px', '400px'] : ['1133px', '350px'],
                            success: function(lay) {
                                var timeDate = data.timeDate && data.timeDate.length && data.timeDate.length > 0 ? data.timeDate : [];
                                var settype = data.timeDate.length > 0 ? data.timeDate[0].settype : '0';
                                var hz = data.timeDate.length > 0 ? data.timeDate[0].hz : 'year';
                                data.settype = settype;
                                data.hz = hz;
                                var temUrl = checking !== '1' ? './task/permanent/view' : './task/permanent/attenceView';
                                view(this.id).render(temUrl,data);
                            }
                        });
                    }
                });
            }
        }
    })

    //去除重复对象
    function deteleObject(obj) {
        var uniques = [];
        var stringify = {};
        for (var i = 0; i < obj.length; i++) {
            var keys = [];
            for(var key in obj[i]) {
                keys.push(key);
            }
            //var keys = Object.keys(obj[i]);
            keys.sort(function(a, b) {
                return (Number(a) - Number(b));
            });
            var str = '';
            for (var j = 0; j < keys.length; j++) {
                str += JSON.stringify(keys[j]);
                str += JSON.stringify(obj[i][keys[j]]);
            }
            if (!stringify.hasOwnProperty(str)) {
                uniques.push(obj[i]);
                stringify[str] = true;
            }
        }
        uniques = uniques;
        return uniques;
    }

})
</script>